<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文本</title>
<link href="../../../static/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
<script type="text/javascript">
function tipOpen(content) {
	$(".tipright p").text(content);
	$("#tip").fadeIn(200);
}
function tipClose() {
	$("#tip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>仓库管理</li>
    <li>出库管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <ul class="tools">
      <li>仓库名称:
        <input maxlength="30" type="text" id="cName" />
      </li>
      <li>订单编号:
        <input maxlength="30" type="text" id="indent" />
      </li>
      <li>状态:
        <select id="state">
        	<option value=""></option>
            <option value="1">未发货</option>
            <option value="2">已发货</option>
            <option value="3">已回款</option>
            <option value="4">取消订单</option>
            <option value="5">已退货</option>
        </select>
      </li>
      <li class="subBut" id="searchBtn"><img src="../../../static/images/t06.png" />查询</li>
      <a href="/storage/delivery/deliveryAdd"><li class="subBut" ><img src="../../../static/images/t01.png" />添加出库</li></a>
    </ul>
    <table id="OutWarehoseList" class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>订单编号</th>
          <th>金额</th>
          <th>仓库名称</th>
          <th>出库时间</th>
          <th>出库人</th>
          <th>状态</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>1</td>
          <td>DJ201701270001</td>
          <td>￥9,876,582</td>
          <td>南京21号仓库</td>
          <td>2013-09-09 15:05:05</td>
          <td>朱元璋</td>
          <td>未发货</td>
          <td>
          	<a href="/storage/delivery/deliveryView" class="tablelink">查看详情</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定此订单发货吗？')">发货</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定取消此订单吗？')">取消订单</a>
          </td>
        </tr>
        <tr>
          <td>2</td>
          <td>DJ201701270002</td>
          <td>￥9,876,582</td>
          <td>武汉71号仓库</td>
          <td>2013-09-09 15:05:05</td>
          <td>周瑜</td>
          <td>已发货</td>
          <td>
          	<a href="/storage/delivery/deliveryView" class="tablelink">查看详情</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定取消此订单吗？')">取消订单</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定收到此订单回款吗？')">确认回款</a>
          </td>
        </tr>
        <tr>
          <td>3</td>
          <td>DJ201701270003</td>
          <td>￥9,876,582</td>
          <td>南京21号仓库</td>
          <td>2013-09-09 15:05:05</td>
          <td>朱元璋</td>
          <td>已回款</td>
          <td>
          	<a href="/storage/delivery/deliveryView" class="tablelink">查看详情</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定取消此订单吗？')">取消订单</a>
          </td>
        </tr>
        <tr>
          <td>4</td>
          <td>DJ201701270004</td>
          <td>￥9,876,582</td>
          <td>武汉71号仓库</td>
          <td>2013-09-09 15:05:05</td>
          <td>周瑜</td>
          <td>取消订单</td>
          <td>
          	<a href="/storage/delivery/deliveryView" class="tablelink">查看详情</a>
            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen('确定收到此订单的退货吗？')">确认已退货</a>
          </td>
        </tr>
        <tr>
          <td>5</td>
          <td>DJ201701270005</td>
          <td>￥9,876,582</td>
          <td>南京21号仓库</td>
          <td>2013-09-09 15:05:05</td>
          <td>朱元璋</td>
          <td>已退货</td>
          <td>
          	<a href="/storage/delivery/deliveryView" class="tablelink">查看详情</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" id="total">0</i>条记录，当前显示第&nbsp;<i class="blue" id="current">1&nbsp;</i>页</div>
      <ul class="paginList" id="pagelistNum">
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">1</a></li>-->
<!--        <li class="paginItem current"><a href="javascript:;">2</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--        <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
      </ul>
    </div>
  </form>
  <!-- 提示框 -->
  <div id="tip" class="tip">
    <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
    <div class="tipinfo"> <span><img src="../../images/ticon.png" /></span>
      <div class="tipright">
        <p></p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="tipClose()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="tipClose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

    var isSerch = false;
    $(function () {
      loadOutstorages(1);
      // 搜索点击事件
      $("#searchBtn").on("click", function () {
        isSerch = true;
        // alert($('#cName').val());
        // alert($('#state').val())
        // alert($('#indent').val());
        loadOutstorages(1);
      })

    });

    //加载仓库列表
    window.lastMoney = new Map();//剩余金额
    function loadOutstorages(currentPage) {
      let cName;
      let state;
      let indent;
      if (isSerch) {
        cName = $('#cName').val();
        state = $('#state').val();
        indent = $('#indent').val();
      }

      let nowUser = JSON.parse(localStorage.getItem("user"));//当前用户
      let nowUserID = nowUser.uid;
      //跳转servlet路径、传入参数、获取返回值——页面片段并显示！
      $.ajax({
        type: "GET",//请求类型
        url: "/OutWarehouse/OutWarehousePage",//请求的url
        data: {
          OrderIDLike: indent,
          State: state,
          cNameLike: cName,
          userID:nowUserID,
          pageNum: currentPage,
          pageSize: 6
        },//请求参数
        dataType: "json",//ajax接口（请求url）返回的数据类型
        success: function (pb) {
          pb = pb.data;
          $("#total").html(pb.totalCount)
          $("#current").html(pb.pageNum)
          //1.展示分页页码
          var lis = "";
          //上一页
          var beforenum = pb.pageNum - 1;
          if (beforenum <= 0) {
            beforenum = 1;
          }
          var beforePage = '<li class="paginItem" onclick="loadOutstorages(' + beforenum + ')"><a href="javascript:;"><span class="pagepre"></span></a></li>';
          lis += beforePage;

          // 1,2,3,4...
          // 定义开始位置begin,结束位置 end
          var begin; // 开始位置
          var end; //  结束位置

          //要显示6个页码
          if (pb.totalPage < 6) {
            //总页码不够10页
            begin = 1;
            end = pb.totalPage;
          } else {
            //总页码超过6页
            begin = pb.pageNum - 3;
            end = pb.pageNum + 2;
            //2.如果前边不够3个，后边补齐6个
            if (begin < 1) {
              begin = 1;
              end = begin + 5;
            }
            //3.如果后边不足2个，前边补齐6个
            if (end > pb.totalPage) {
              end = pb.totalPage;
              begin = end - 5;
            }
          }
          for (var i = begin; i <= end; i++) {
            var li;
            //判断当前页码是否等于i
            if (pb.pageNum == i) {
              li = '<li class="paginItem current" onclick="loadOutstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            } else {
              //创建页码的li
              li = '<li class="paginItem" onclick="loadOutstorages(' + i + ')"><a href="javascript:;">' + i + '</a></li>';
            }
            //拼接字符串，加入页面中
            lis += li;
          }

          //下一页
          var nextnum = pb.pageNum + 1;
          if (nextnum > pb.totalPage) {
            nextnum = pb.totalPage;
          }
          var nextPage = '<li class="paginItem" onclick="loadOutstorages(' + nextnum + ')"><a href="javascript:;"><span class="pagenxt"></span></a></li>';
          lis += nextPage;

          $("#pagelistNum").html(lis);//显示

          // 3.显示当前页列表
          let Outstorage_lis = '';

          for (var i = 0; i < pb.data.length; i++) {

            var storage = pb.data[i];//该页路线数据显示        showOrder(id)


            let states = "";
            let action='<a href="/market/order/orderView?orderid='+storage.indent+'" class="tablelink">查看详情</a>';

            switch (storage.state) {
              case "1":
                states="未发货"
                action+='<a href="javascript:;" name="'+storage.id+'" onclick="updateStatesOut(this)"  ' +
                        'state="'+storage.state+'" action="f"  wid="'+storage.wid+'" indent="'+storage.indent+'" class="tablelink">发货</a>&nbsp;&nbsp;'
                action+='<a href="javascript:;" name="'+storage.id+'" onclick="updateStatesOut(this)"  ' +
                        'state="'+storage.state+'" action="q" wid="'+storage.wid+'" indent="'+storage.indent+'" class="tablelink">取消订单</a>&nbsp;&nbsp;'
                break;
              case "2":
                states="已发货"
                action+='<a href="javascript:;" name="'+storage.id+'" onclick="updateStatesOut(this)"  ' +
                        'state="'+storage.state+'" action="q" wid="'+storage.wid+'" indent="'+storage.indent+'" class="tablelink">取消订单</a>&nbsp;&nbsp;'
                action+='<a href="javascript:;" name="'+storage.id+'" onclick="updateStatesOut(this)"  ' +
                        'state="'+storage.state+'" action="h" wid="'+storage.wid+'" indent="'+storage.indent+'" class="tablelink">确认回款</a>&nbsp;&nbsp;'
                break;
              case "3":
                states="已回款"
                break;
              case "4":
                states="取消订单"
                action+='<a href="javascript:;" name="'+storage.id+'" onclick="updateStatesOut(this)"  ' +
                        'state="'+storage.state+'" action="t" wid="'+storage.wid+'" indent="'+storage.indent+'" class="tablelink">确认已退货</a>&nbsp;&nbsp;'
                break;
              case "5":
                states="已退款"
                break;
            }

            var storageli =
                    '<tr>' +
                    '<td>' +
                    '<span>' + ((pb.pageNum - 1) * 6 + i + 1) + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.indent + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.ordermoney + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.cname + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.outTime + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + storage.userName + '</span>' +
                    '</td>' +
                    '<td>' +
                    '<span>' + states + '</span>' +
                    '</td>' +
                    '<td>'
                    + action+
                    '</td>' +
                    '</tr>';
            Outstorage_lis += storageli;
          }
          $("#OutWarehoseList tbody").html(Outstorage_lis);

        }
      })

    }

    //跳转详情页
    function toDetail(target){
      let index=$(target).parents("tr").index();
      sessionStorage.setItem("detailInfo",JSON.stringify(datas.resultInfo.data[index]));
      location.href="/market/customer/customerView";
    }

    function updateStatesOut(a) {//点击更新状态
      // alert($(a).attr('indent'))
      // alert($(a).attr('state'))
      // alert($(a).attr('wid'))
      // alert($(a).attr('action'))
      let oldState=$(a).attr('state');
      let action=$(a).attr('action');
      let newState;
      if(oldState=="1"&&action=="q")
        newState="5"
      if(oldState=="1"&&action=="f")
        newState="2"
      if(oldState=="2"&&action=="h")
        newState="3"
      if(oldState=="2"&&action=="q")
        newState="4"
      if(oldState=="4"&&action=="t")
        newState="5"
      // let Nowmoney=lastMoney.get($(a).attr('indent'))
      // if(Nowmoney>0){//余额充足
        //减去金额，加库存，改状态
        $.ajax({
          url: "/OutWarehouse/updateOutWarehouseState",
          type: "get",
          data:{
            orderid:$(a).attr('indent'),
            State:oldState,
            NewState:newState,
            WarehouseID:$(a).attr('wid'),
            // lastWmoney:Nowmoney
          },
          dataType: "json",
          success: (pb) => {
           alert(pb.msg)
              loadOutstorages(1)
          }
        })
      // }else
      //   alert("当前仓库余额不足！")
    }
</script>
</body>
</html>
